﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using Jalal.Library.Utility;
using Jalal.Library.Data;
using System.Data.Common;

namespace BCGC.DAL
{
    public class PostCategoryData
    {
        public static int CreatePostCategory(string categoryName,string description,int totalPost,bool isActive)
        {
            object id = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_CreatePostCategory";

            dataMiner.AddParameter(command, "@CategoryName", DbType.String, 100, ParameterDirection.Input, categoryName);
            dataMiner.AddParameter(command, "@Description", DbType.String, 500, ParameterDirection.Input, description);
            dataMiner.AddParameter(command, "@TotalPost", DbType.Int32, 0, ParameterDirection.Input, totalPost);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out id);

            return (int)CommonUtility.FilterNull(id, typeof(int));
        }

        public static bool UpdatePostCategory(int categoryID,string categoryName, string description,int totalPost, bool isActive)
        {
            object count = null;
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_UpdatePostCategory";

            dataMiner.AddParameter(command, "@CategoryID", DbType.Int32, 0, ParameterDirection.Input, categoryID);
            dataMiner.AddParameter(command, "@CategoryName", DbType.String, 100, ParameterDirection.Input, categoryName);
            dataMiner.AddParameter(command, "@Description", DbType.String, 0, ParameterDirection.Input, description);
            dataMiner.AddParameter(command, "@TotalPost", DbType.Int32, 0, ParameterDirection.Input, totalPost);
            dataMiner.AddParameter(command, "@IsActive", DbType.Boolean, 0, ParameterDirection.Input, isActive);
            dataMiner.AddParameter(command, "ReturnValue", DbType.Int32, 0, ParameterDirection.ReturnValue, null);
            dataMiner.Execute(command, out count);
            if (count == null)
                return false;
            else
                return (((int)count == 0) ? false : true);
        }

        public static DataTable GetAllPostCategory()
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetAllPostCategory";
            return dataMiner.GetListData(command);
        }

        public static DataTable GetPostCategoryByID(int id)
        {
            DataMiner dataMiner = DataFactory.GetDataMiner();
            DbCommand command = DataFactory.GetCommand();
            command.CommandText = "CSP_GetPostCategoryByID";
            dataMiner.AddParameter(command, "@CategoryID", DbType.Int32, 0, ParameterDirection.Input, id);
            return dataMiner.GetListData(command);
        }
    }
}
